package com.zhiyou100.controller;

import com.zhiyou100.entity.Dept;
import com.zhiyou100.service.DeptService;
import com.zhiyou100.service.impl.DeptServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/deptServlet")   //注解版servlet ---不用配置了
public class DeptServlet extends HttpServlet {
     DeptService deptService=new DeptServiceImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     //调用service层的方法
        List<Dept> allDept = deptService.getAllDept();
        System.out.println("agfuiagyfiuagfiagfiagf");
     //存入request域
     request.setAttribute("allDept",allDept);
     //跳转
     request.getRequestDispatcher("index.jsp").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       doPost(request,response);
    }
}
